<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <style>
      img {
        width: 100px;
        height: 100px;
      }
    </style>
    <input type="file" id="upload" multiple />
    <button id="btn"></button>
    <div class="showImg"></div>
    <script>
      var upload = document.querySelector("#upload");
      var showImg = document.querySelector(".showImg");
      var btn = document.getElementById("btn");
      let file = null;
      upload.onchange = function (e) {
        var a = this.files;
        file = this.files[0];
        var url = "";
        var img = "";
        var formdata = new FormData();
        console.log(this.files);

        a = [...a];
        console.log(a);

        a.forEach((value) => {
          url = window.URL.createObjectURL(value);

          img += `<img src='${url}' />`;
          console.log(img);
        });
        showImg.innerHTML = img;
      };
      btn.onclick = function () {
        let formdata = new FormData();
        formdata.append("file", file);
        console.log(formdata);
      };
    </script>
  </body>
</html>
